﻿using System;
using Xamarin.Forms;

namespace SharpDepend.XamarinForms.Controls
{
    class InputBox : Grid
    {
        private Entry entry;

        public event Action<string> OnInputActionDone;

        public InputBox(string label, string defaultInput)
        {
            RowDefinitions.Add(new RowDefinition());
            RowDefinitions.Add(new RowDefinition { Height = 150 });
            RowDefinitions.Add(new RowDefinition());

            StackLayout stack = new StackLayout();
            Grid.SetRow(stack, 1);
            Children.Add(stack);

            Label lab = new Label();
            lab.Text = label;
            stack.Children.Add(lab);

            entry = new Entry();
            entry.Text = defaultInput;
            stack.Children.Add(entry);

            Button done = new Button();
            done.Text = "Done";
            done.Clicked += Done_Clicked;
            done.HorizontalOptions = LayoutOptions.End;
            stack.Children.Add(done);
        }

        private void Done_Clicked(object sender, EventArgs e)
        {
            var call = OnInputActionDone;
            if (call != null)
            {
                call(entry.Text);
            }
        }
    }
}
